package com.industry.system.controller;

import com.industry.framework.common.Result;
import com.industry.framework.common.page.PageQuery;
import com.industry.framework.common.page.TableDataInfo;
import com.industry.system.controller.vo.MenuTreeRespVO;
import com.industry.system.controller.vo.RoleMenuVo;
import com.industry.system.controller.vo.RoleVo;
import com.industry.system.convert.SystemRoleConvert;
import com.industry.system.dal.dataobject.SystemMenu;
import com.industry.system.dal.dataobject.SystemRole;
import com.industry.system.dal.dataobject.SystemRoleMenu;
import com.industry.system.service.SystemRoleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.industry.framework.common.Result.fail;
import static com.industry.framework.common.Result.success;
/**
 * @Author nbZhuozh
 * @Date 2025-02-13  21:00
 **/
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private SystemRoleService systemRoleService;

    //根据id 获取角色
    @GetMapping("/query-role-byId")
    public Result<RoleVo> queryRoleById(@RequestParam("roleId") Long roleId){
        return success(SystemRoleConvert.INSTANCE.convert(systemRoleService.queryRoleById(roleId)));
    }


    //根据当前用户部门 获取部门下的角色列表
    @GetMapping("/query-role-list")
    public Result<TableDataInfo<RoleVo>> queryRoleList(PageQuery pageQuery){
        return success(systemRoleService.queryRoleList(pageQuery));
    }

    //新增角色
    @PostMapping("/insert")
    public Result<String> insert(@RequestBody RoleMenuVo systemRole){
        return systemRoleService.insert(systemRole) ? success("success") : fail("fail");
    }

    //修改角色
    @PostMapping("/modify")
    public Result<String> modify(@RequestBody RoleMenuVo systemRole){
        systemRoleService.modify(systemRole);
        return success();
    }


    //获取角色对应菜单
    @GetMapping("query-role-menu-infos-by-roleId")
    public Result<List<SystemMenu>> queryRoleMenuInfosByRoleId(@RequestParam("roleId") String roleId){
       return Result.success(systemRoleService.getRoleMenuInfosByRoleId(roleId));
    }
}
